package com.sky.mapper;

import com.sky.dto.DishDTO;
import com.sky.dto.DishPageQueryDTO;
import com.sky.entity.Dish;
import com.sky.vo.DishVO;
import org.apache.ibatis.annotations.*;

import java.time.LocalDateTime;
import java.util.List;

@Mapper
public interface DishesMapper {
    List<Dish> page(DishPageQueryDTO dishPageQueryDTO);

    @Options(useGeneratedKeys = true, keyProperty = "id")
    @Insert("insert into dish (name,category_id,price,image," +
            "description,status,create_time,update_time,create_user" +
            ",update_user)" +
            " values (#{name}, #{categoryId}, #{price}, #{image}," +
            " #{description}, #{status}, #{createTime}, #{updateTime}," +
            " #{createUser}, #{updateUser})")
    void addDishes(Dish dish);

    void deleteDishes(List<Integer> ids);

    void updateDishes(DishDTO dishDTO, LocalDateTime now);

    @Select("select * from dish where id = #{id}")
    Dish getById(Integer id);

    @Select("select * from dish where category_id = #{categoryId}" +
            " and status = 1")
    List<DishVO> findByList(Integer categoryId);

    @Update("update dish set status = #{status} where id = #{id}")
    void updateStatus(Integer status, Integer id);

    List<Dish> list(Dish dish);
}
